import { request, METHOD } from '@/utils/request';
// import qs from 'qs';
// 角色列表
export const getListRoleApi = (params) => {
  return request('/rbac/rbacRole/list', METHOD.GET, params);
};
// 树形结构返回所有菜单列表
export const getTreeListApi = (params) => {
  return request('/rbac/rbacMenu/treeList', METHOD.GET, params);
};
// 新增
export const addRoleApi = (params) => {
  return request('/rbac/rbacRole/create', METHOD.POST, params);
};
// 删除
export const delRoleApi = (params) => {
  return request(`/rbac/rbacRole/delete?ids=${params.ids}`, METHOD.POST);
};

// 编辑
export const updateRoleApi = (params) => {
  return request(`/rbac/rbacRole/update/${params.id}`, METHOD.POST, params);
};
// 分配
export const allocMenuApi = (params) => {
  const { roleId, menuIds } = params;
  let t = '';
  menuIds.forEach(item => {
    t += `&menuIds=${item}`;
  });

  return request(`/rbac/rbacRole/allocMenu?roleId=${roleId}${t}`, METHOD.POST, params);
};

// 获取权限
export const getListMenuApi = ({ roleId }) => {
  return request(`/rbac/rbacRole/listMenu/${roleId}`, METHOD.GET);
};

// 添加角色资源
export const addResourceApi = (params) => {
  return request('/rbac/rbacRole/resource/addResource', METHOD.POST, params);
};

// 获取资源
export const listResourceApi = (params) => {
  return request('/rbac/rbacRole/resource/listResource', METHOD.GET);
};

// 修改角色
export const updateResourceApi = (params) => {
  return request(`/rbac/rbacRole/resource/update/${params.id}`, METHOD.POST, params);
};

// 根据角色获取资源回显
export const listRoleResourceByRoleIdApi = (params) => {
  return request('/rbac/rbacRole/resource/listRoleResourceByRoleId', METHOD.GET, params);
};

